package com.jjkj.environmental.environmental.ui.base

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.jjkj.environmental.environmental.di.ActivityComponent
import com.jjkj.environmental.environmental.di.DaggerActivityComponent
import com.jjkj.environmental.environmental.presenter.base.BasePresenter
import com.jjkj.environmental.environmental.utils.ActivityHelper
import com.jjkj.environmental.environmental.view.base.BaseView
import javax.inject.Inject

/**
 * 自定义activity基类
 * @author Administrator
 */
abstract class BaseActivity<V : BaseView<*>, P : BasePresenter<V>> : AppCompatActivity() {

    @Inject
    lateinit var mPresenter: P

    init {
        this.initInject()
    }

    abstract fun initInject()

    @Suppress("UNCHECKED_CAST")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mPresenter.bindView(this as V)
        ActivityHelper.addActivity(this)
    }


    fun getPresenter(): P {
        return this.mPresenter
    }

    override fun onDestroy() {
        mPresenter.unbindView()
        ActivityHelper.removeActivity(this)
        super.onDestroy()
    }

    protected fun getComponent(): ActivityComponent {
        return DaggerActivityComponent.create()
    }
}
